<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-11-23
 * Time: 13:58
 */

namespace App\Libs;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\FirePHPHandler;

class Log
{
    public static function get($name, $dir = null) {
        $logger = new Logger($name);
        $date = date('Y-m-d', time());
        $file_name = $name . '_' . $date . '.log';
        $path = storage_path() . '/logs/' . ($dir ? ($dir . '/') : '') . $file_name;
        $stream = new StreamHandler($path, Logger::INFO);
        $firephp = new FirePHPHandler();
        $logger->pushHandler($stream);
        $logger->pushHandler($firephp);
        return $logger;
    }
}